package com.chtw.vuedemo.response;

import com.chtw.vuedemo.response.enumutil.CodeAndMsg;
import lombok.Data;

/**
 * @author chtw
 * @date 2020-09-27 23:45
 */
@Data
public class RespUtil<T> {
    private int code;
    private String msg;
    private T data;

    public RespUtil(CodeAndMsg code, T data){
        this.code = code.getCode();
        this.msg = code.getMessage();
        this.data = data;
    }
    public RespUtil(int code,String msg){
        this.code = code;
        this.msg = msg;
        this.data = null;
    }
    public RespUtil(T data){
        this.code = CodeAndMsg.SUCCESS.getCode();
        this.msg = CodeAndMsg.SUCCESS.getMessage();
        this.data = data;
    }

    public static<T> RespUtil<T>  success(T data){
        return new RespUtil<> (data);
    }

    public static<T> RespUtil<T> fail(String msg){
        return new RespUtil<> (CodeAndMsg.FAIL.getCode(), msg);
    }
}
